/// @tags:
#include <cctype>
#include <cstdio>
#include <cstring>

int const N = 1e5 + 5;

template <typename T>
inline T &read(T &x) {
  x = 0;
  bool f = false;
  short ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = true;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + (ch ^ '0'), ch = getchar();
  if (f) x = -x;
  return x;
}

int n, q;
int nxt[N];
char str[N], s[N];

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("string.in", "r", stdin);
  freopen("string.out", "w", stdout);
#endif
#endif

  read(n), read(q);
  scanf("%s", str + 1);
  for (int l, r; q; --q) {
    read(l), read(r);
    if (r == l) {
      puts("-1");
      continue;
    }
    strncpy(s + 1, str + l, r - l + 1);
    memset(nxt, 0, sizeof(int) * (n + 1));
    int len1 = n, len2 = r - l + 1;
    for (int i = 2, j = 0; i <= len2; ++i) {
      while (j && s[j + 1] != s[i]) j = nxt[j];
      if (s[j + 1] == s[i]) ++j;
      nxt[i] = j;
    }
    int pos = -1, ans = 0;
    for (int i = 1, j = 0; i <= len1; ++i) {
      while (j && s[j + 1] != str[i]) j = nxt[j];
      if (s[j + 1] == str[i]) ++j;
      if (j == len2) {
        j = nxt[j];
        if (pos == -1) {
          pos = i;
          ans++;
        } else if (pos <= i - len2 + 1) {
          ++ans;
          pos = i;
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}